﻿@using fqlmoney.Model
@using fqlmoney.Common
@{
    ViewBag.Title = "分类设置";
    ViewBag.Menu = "type";
    List<user_moneytype> list = ViewBag.list;
}
@section fqlmoneyCss{
    <style>
       .m-b {
            margin-bottom: 15px;
        }
       .b-p{padding:0px 5px;}
        .pull-in {
            margin-left: -15px;
            margin-right: -15px;
        }
        .bs-example {
            position: relative;
            padding: 20px 35px 15px;
            margin: 0 -15px 15px;
            border-style: solid;
            margin-right: 0;
            margin-left: 0;
            background-color: #fff;
            border-color: #ddd;
            border-width: 1px;
            border-radius: 4px 4px 0 0;
            -webkit-box-shadow: none;
            box-shadow: none;
        }
    </style>
}
<div class="row">
    <div class="col-sm-9">
        <div class="bs-example" data-example-id="inline-code">


            <div class="table-responsive">
                <table class="table table-condensed">
                    <thead>
                        <tr>
                            <th>名称</th>
                            <th>收支</th>
                            <th>删除</th>
                            <th>修改</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in list)
                    {
                            <tr>
                                <td>@item.t_name</td>
                                <td>@(item.t_state == 1 ? "收入" : "支出")</td>
                                <td><button type="button" data-id="@item.t_id" class="btn btn-danger b-p typedel"><i class="fa fa-times"></i></button></td>
                                <td><button type="button" data-id="@item.t_id" data-name="@item.t_name" data-state="@item.t_state" class="btn btn-info b-p typeedit"><i class="fa fa-edit"></i></button></td>
                            </tr>
                    }
                    </tbody>
                </table>
                @Html.Raw(MyHtmlHelper.ShowPageNavigate(ViewBag.request_url,ViewBag.page, (int)ViewBag.pagesize, (long)ViewBag.totalcount, (string)ViewBag.search_url))
            </div>
        </div>
    </div>
    <div class="col-sm-3">
        <div class="panel panel-default">
            <div class="panel-heading">分类设置</div>
            <div class="panel-body">
                <div class="form-group pull-in clearfix">
                    <div class="col-sm-12">
                        <div class="input-group m-b">
                            <span class="input-group-addon">收支</span>
                            <select class="form-control input-sm"  id="typestate" name="typestate">
                                <option value="2">支出</option>
                                <option value="1">收入</option>
                            </select>
                        </div>
                    </div>
                        
                    <div class="col-sm-12">
                        <div class="input-group m-b">
                            <span class="input-group-addon">名称</span>
                            <input class="form-control" id="typename" maxlength="20" name="typename" type="text" value="">
                        </div>
                    </div>
                </div>
                <div class="form-group text-right">
                    <input type="hidden" id="typeid" value="0" />
                    <button class="btn btn-default pull-left canclesave">放弃保存</button>
                    <button class="btn btn-success typesave">新增保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

@section fqlmoneyScript{
    <script>
        $(function () {
            $("button.canclesave").click(function () {
                $("#typeid").val(0);
                $("#typename").val("");
                $(".typesave").text("新增保存");
            });
            $("button.typeedit").click(function () {
                var obj = $(this);
                $("#typeid").val(obj.attr("data-id"));
                $("#typename").val(obj.attr("data-name"));
                $("#typestate").val(obj.attr("data-state"));
                $(".typesave").text("编辑保存");
            });

            $("button.typesave").click(function(){
                var tid=$("#typeid").val();
                var typename=$("#typename").val();
                if(typename=="")
                {
                    $("#typename").focus();
                    return;
                }
                var list={"t_id":tid,"t_name":typename,"t_state":$("#typestate").val()};
                var url="";
                if(tid==0)
                {
                    url="/Type/Add";
                }
                else{
                    url="/Type/Update";
                }
                $.post(url,list,function(data){
                    alert(data.msg);
                    location.reload();
                });
            });

            $("button.typedel").click(function(){
                if(confirm('确定删除该条数据'))
                {
                    $.post("/Type/Delete",{"id":$(this).attr("data-id")},function(data){
                        alert(data.msg);
                        location.reload();
                    });
                }
            });
        });
        
    </script>
}
